//
//  ViewController.m
//  iOSBase
//
//  Created by mac on 2018/1/9.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *phoneTF;
@property (weak, nonatomic) IBOutlet UITextField *pwdTF;

@property (weak, nonatomic) IBOutlet UIImageView *img1;
@property (weak, nonatomic) IBOutlet UIImageView *img2;
@property (weak, nonatomic) IBOutlet UIImageView *img3;
@property (weak, nonatomic) IBOutlet UIImageView *img4;

@property (weak, nonatomic) IBOutlet UIImageView *img5;
@property (weak, nonatomic) IBOutlet UIImageView *img6;
@property (weak, nonatomic) IBOutlet UIImageView *img7;
@property (weak, nonatomic) IBOutlet UIImageView *img8;
@property (weak, nonatomic) IBOutlet UIImageView *img9;
@property (weak, nonatomic) IBOutlet UITextField *codeTF;


@property(nonatomic,strong)NSString *appkey;
@property(nonatomic,strong)NSString *mac;
@property(nonatomic,strong)NSString *macKey;
@property(nonatomic,strong)NSString *device_id;
@property(nonatomic,strong)NSString *device_ip;

@property(nonatomic,strong)NSString *machine_id;
@property(nonatomic,strong)NSArray *machine_img_array;

@property(nonatomic,strong)NSString *phone;
@property(nonatomic,strong)NSString *session_id;
@property(nonatomic,strong)NSString *lifetime;
@property(nonatomic,strong)NSString *request_url;
@property(nonatomic,strong)NSString *username;
@property(nonatomic,strong)NSString *user_id;

@property(nonatomic,strong)NSString *process_number;
@property(nonatomic,strong)NSString *invest_type;
@end
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    //http://47.92.36.209:4455
    //http://39.100.201.239:5588
    NSArray *views = @[_img1,_img2,_img3,_img4,_img5,_img6,_img7,_img8,_img9];
    for (NSInteger i = 0; i < 9; i ++) {
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickAction:)];
        UIImageView *img = (UIImageView *)views[i];
        img.userInteractionEnabled = YES;
        img.tag = 100+i;
        [img addGestureRecognizer:tap];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
   
}

- (void)clickAction:(UITapGestureRecognizer *)tap {
    UIImageView *img = (UIImageView *)tap.view;
    img.hidden = YES;
}

- (IBAction)人机验证:(id)sender {
    _img1.hidden = NO;
    _img2.hidden = NO;
    _img3.hidden = NO;
    _img4.hidden = NO;
    _img5.hidden = NO;
    _img6.hidden = NO;
    _img7.hidden = NO;
    _img8.hidden = NO;
    _img9.hidden = NO;
    /*
     appkey    5fe9a5cebe05a73c51a6edb18214a6681586481306 （自动生成  32位随机 + 当前时间戳 10 ）
     session_id
     user_id
     language    zh
     platform    ios
     randkey    ios 1.0.3
     app_version    1.0.3
     mac    b60cfd773dfc428dd3d705cde1c67f7f  （自动生成）
     mackey    14MThBQkVEOEQtODI4RC00QjZELTkzQTEtQjBGQjg0MDgyMzg5108  （自动生成 数字—+ 中间串 + 5 +3位数字）
     device_id    18ABED8D-828D-4B6D-93A1-B0FB84082389 （自动生成）
     device_ip    192.168.0.102 （自动生成）
     */
    _appkey = [self serial];
    _mac = [self mac];
    _macKey = [NSString stringWithFormat:@"%u%@%u",arc4random_uniform((u_int32_t)99),@"MThBQkVEOEQtODI4RC00QjZELTkzQTEtQjBGQjg0MDgyMzg",arc4random_uniform((u_int32_t)999 + 5000)];
    _device_id = [self get_device_id];
    _device_ip = [self get_device_ip];
    
    RequestParams *params = [[RequestParams alloc] initWithParams:@"http://39.100.201.239:5588/api/api.php?action=machine_init"];
    [params addParameter:@"appkey" value:_appkey]; //
    [params addParameter:@"session_id" value:@""];
    [params addParameter:@"user_id" value:@""];
    [params addParameter:@"language" value:@"zh"];
    [params addParameter:@"platform" value:@"ios"];
    [params addParameter:@"randkey" value:@"ios 1.0.3"];
    [params addParameter:@"app_version" value:@"1.0.3"];
    [params addParameter:@"mac" value:_mac];//
    [params addParameter:@"mackey" value:_macKey];//
    
    [params addParameter:@"device_id" value:_device_id];//
    [params addParameter:@"device_ip" value:_device_ip];//
    [[NetworkSingleton shareInstace] sessionPost:params withTitle:@"" successBlock:^(id data) {
        NSDictionary *dic = [NSDictionary dictionaryWithDictionary:data];
        NSLog(@"人机验证数据==%@",dic);
        NSString *code = dic[@"code"];
        if ([code isEqualToString:@"5000"]) {
            [SVProgressHUD showSuccessWithStatus:dic[@"data"][0][@"machine_quetion"]];
            [_img1 sd_setImageWithURL:[NSURL URLWithString:dic[@"data"][0][@"machine_img_array"][0][@"img"]]];
            [_img2 sd_setImageWithURL:[NSURL URLWithString:dic[@"data"][0][@"machine_img_array"][1][@"img"]]];
            [_img3 sd_setImageWithURL:[NSURL URLWithString:dic[@"data"][0][@"machine_img_array"][2][@"img"]]];
            [_img4 sd_setImageWithURL:[NSURL URLWithString:dic[@"data"][0][@"machine_img_array"][3][@"img"]]];
            [_img5 sd_setImageWithURL:[NSURL URLWithString:dic[@"data"][0][@"machine_img_array"][4][@"img"]]];
            [_img6 sd_setImageWithURL:[NSURL URLWithString:dic[@"data"][0][@"machine_img_array"][5][@"img"]]];
            [_img7 sd_setImageWithURL:[NSURL URLWithString:dic[@"data"][0][@"machine_img_array"][6][@"img"]]];
            [_img8 sd_setImageWithURL:[NSURL URLWithString:dic[@"data"][0][@"machine_img_array"][7][@"img"]]];
            [_img9 sd_setImageWithURL:[NSURL URLWithString:dic[@"data"][0][@"machine_img_array"][8][@"img"]]];
            _machine_img_array = [NSArray arrayWithArray:dic[@"data"][0][@"machine_img_array"]];
            _machine_id = dic[@"data"][0][@"machine_id"];
        }else {
            [SVProgressHUD showErrorWithStatus:dic[@"msg"]];
        }
        
        
    } failureBlock:^(NSError *error) {
        
    }];
}

- (IBAction)刷新:(id)sender {

}

- (IBAction)获取验证码:(id)sender {

    /*
     appkey    5fe9a5cebe05a73c51a6edb18214a6681586481306 （与上一接口一致）
     session_id
     user_id
     language    zh
     platform    ios
     randkey    ios 1.0.3
     app_version    1.0.3
     mac    b60cfd773dfc428dd3d705cde1c67f7f （与上一接口一致）
     mackey    61MThBQkVEOEQtODI4RC00QjZELTkzQTEtQjBGQjg0MDgyMzg5939 （与上一接口一致）
     login_type    mobile
     location    00
     phone    15674522640
     email    15674522640
     password    wy123456
     machine_id    0b1c295e621bd1761f142c4dfbab0c41a7c277bacbb5c57252b89bdc519f98be （从上面接口获取）
     machine_value    6359ea4d7b26230258fd6f90ebf783d9c40d30e567d1bbdf61eb0fd9e40a9d51ecb9dba309599474fe368a5811c55d5a054db6eadf7b311a4c87b2c77294341a4d6df96268fa618ebb6c8ae7b5460380（将图片value拼接）
     */
    RequestParams *params = [[RequestParams alloc] initWithParams:@"http://39.100.201.239:5588/api/api.php?action=login"];
    [params addParameter:@"appkey" value:_appkey]; //
    [params addParameter:@"session_id" value:@""];
    [params addParameter:@"user_id" value:@""];
    [params addParameter:@"language" value:@"zh"];
    [params addParameter:@"platform" value:@"ios"];
    [params addParameter:@"randkey" value:@"ios 1.0.3"];
    [params addParameter:@"app_version" value:@"1.0.3"];
    [params addParameter:@"mac" value:_mac];//
    [params addParameter:@"mackey" value:_macKey];//
    [params addParameter:@"login_type" value:@"mobile"];//
    [params addParameter:@"location" value:@"00"];//
    [params addParameter:@"phone" value:_phoneTF.text];//
    [params addParameter:@"email" value:_phoneTF.text];//
    [params addParameter:@"password" value:@"wy123456"];//_pwdTF.text
    [params addParameter:@"machine_id" value:_machine_id];//
    
    NSArray *views = @[_img1,_img2,_img3,_img4,_img5,_img6,_img7,_img8,_img9];
    NSMutableArray *array = [NSMutableArray array];
    for (UIImageView *sub in views) {
        if (sub.hidden) {
            [array addObject:_machine_img_array[[views indexOfObject:sub]][@"value"]];
        }
    }
    [params addParameter:@"machine_value" value:[array componentsJoinedByString:@""]];//
    [[NetworkSingleton shareInstace] sessionPost:params withTitle:@"" successBlock:^(id data) {
        NSDictionary *dic = [NSDictionary dictionaryWithDictionary:data];
        NSString *code = dic[@"code"];
        if ([code isEqualToString:@"5000"]) {
            [SVProgressHUD showSuccessWithStatus:@"获取验证码成功"];
            _phone = dic[@"data"][0][@"phone"];
            _session_id= dic[@"data"][0][@"session_id"];
            _lifetime= dic[@"data"][0][@"lifetime"];
            _request_url= dic[@"data"][0][@"request_url"];
            _user_id= dic[@"data"][0][@"username"];
        }else {
            [SVProgressHUD showErrorWithStatus:dic[@"msg"]];
        }
    } failureBlock:^(NSError *error) {
        
    }];
    
}

- (IBAction)登录:(id)sender {
    /*
     appkey    27fb078e2e03e748b42c59d13c5406571586481990  （与上一接口一致）
     session_id    39ec921234336612cb4c77e96cc0ab2f65926dd2138d160cbc （从上接口获取）
     user_id    31881399  （从上接口获取）
     language    zh
     platform    ios
     randkey    ios 1.0.3
     app_version    1.0.3
     mac    b60cfd773dfc428dd3d705cde1c67f7f  （与上一接口一致）
     mackey    31MThBQkVEOEQtODI4RC00QjZELTkzQTEtQjBGQjg0MDgyMzg5287  （与上一接口一致）
     location
     phone    +86 156******2640  （从上接口获取）
     email
     phone_code    646421 （验证码）
     email_code
     google_code
     */
    RequestParams *params = [[RequestParams alloc] initWithParams:@"http://39.100.201.239:5588/api/api.php?action=login_check"];
    [params addParameter:@"appkey" value:_appkey]; //
    [params addParameter:@"session_id" value:_session_id];
    [params addParameter:@"user_id" value:_user_id];
    [params addParameter:@"language" value:@"zh"];
    [params addParameter:@"platform" value:@"ios"];
    [params addParameter:@"randkey" value:@"ios 1.0.3"];
    [params addParameter:@"app_version" value:@"1.0.3"];
    [params addParameter:@"mac" value:_mac];//
    [params addParameter:@"mackey" value:_macKey];
    
    [params addParameter:@"location" value:@""];//
    [params addParameter:@"phone" value:_phone];//
    [params addParameter:@"email" value:@""];//
    [params addParameter:@"phone_code" value:_codeTF.text];//
    [params addParameter:@"email_code" value:@""];//
    [params addParameter:@"google_code" value:@""];//
    
    [[NetworkSingleton shareInstace] sessionPost:params withTitle:@"" successBlock:^(id data) {
        NSDictionary *dic = [NSDictionary dictionaryWithDictionary:data];
        NSString *code = dic[@"code"];
        if ([code isEqualToString:@"5000"]) {
             [SVProgressHUD showSuccessWithStatus:@"登录成功"];
        }else {
            [SVProgressHUD showErrorWithStatus:dic[@"msg"]];
        }
        
        
    } failureBlock:^(NSError *error) {
        
    }];
}

- (IBAction)签到:(id)sender {
    
    /*
     appkey    27fb078e2e03e748b42c59d13c5406571586481990
     session_id    39ec921234336612cb4c77e96cc0ab2f65926dd2138d160cbc
     user_id    31881399
     language    zh
     platform    ios
     randkey    ios 1.0.3
     app_version    1.0.3
     mac    b60cfd773dfc428dd3d705cde1c67f7f
     mackey    4MThBQkVEOEQtODI4RC00QjZELTkzQTEtQjBGQjg0MDgyMzg5765
     number    318813992 （id + 数字）
     date    20200410  （时间）
     */
    RequestParams *params = [[RequestParams alloc] initWithParams:@"http://39.100.201.239:5588/api/api.php?action=candy_get"];
    [params addParameter:@"appkey" value:_appkey]; //
    [params addParameter:@"session_id" value:_session_id];
    [params addParameter:@"user_id" value:_user_id];
    [params addParameter:@"language" value:@"zh"];
    [params addParameter:@"platform" value:@"ios"];
    [params addParameter:@"randkey" value:@"ios 1.0.3"];
    [params addParameter:@"app_version" value:@"1.0.3"];
    [params addParameter:@"mac" value:_mac];//
    [params addParameter:@"mackey" value:_macKey];//
    
    [params addParameter:@"number" value:_user_id];//
    [params addParameter:@"date" value:[Util timestampToString:[Util timeToTurnTheTimestamp] formatterString:@"yyyyMMdd"]];
    
    [[NetworkSingleton shareInstace] sessionPost:params withTitle:@"" successBlock:^(id data) {
        NSDictionary *dic = [NSDictionary dictionaryWithDictionary:data];
        NSString *code = dic[@"code"];
        if ([code isEqualToString:@"5000"]) {
            [SVProgressHUD showSuccessWithStatus:@"签到成功"];
        }else {
            [SVProgressHUD showErrorWithStatus:dic[@"msg"]];
        }
    } failureBlock:^(NSError *error) {
        
    }];
    
}

- (IBAction)投资:(id)sender {
  
    RequestParams *params = [[RequestParams alloc] initWithParams:@"http://39.100.201.239:5588/api/api.php?action=invest_init"];
    [params addParameter:@"appkey" value:_appkey]; //
    [params addParameter:@"session_id" value:_session_id];
    [params addParameter:@"user_id" value:_user_id];
    [params addParameter:@"language" value:@"zh"];
    [params addParameter:@"platform" value:@"ios"];
    [params addParameter:@"randkey" value:@"ios 1.0.3"];
    [params addParameter:@"app_version" value:@"1.0.3"];
    [params addParameter:@"mac" value:_mac];//
    [params addParameter:@"mackey" value:_macKey];//
    
    [params addParameter:@"coin_type" value:@"BTC"];//
    [params addParameter:@"invest_type" value:@"2"];
    
    [[NetworkSingleton shareInstace] sessionPost:params withTitle:@"" successBlock:^(id data) {
        NSDictionary *dic = [NSDictionary dictionaryWithDictionary:data];
        NSString *code = dic[@"code"];
        if ([code isEqualToString:@"5000"]) {
            [SVProgressHUD showSuccessWithStatus:@"invest-init 成功"];
            _process_number= dic[@"data"][0][@"process_number"];
            _invest_type= dic[@"data"][0][@"invest_type"];
            [self renji];
        }else {
            [SVProgressHUD showErrorWithStatus:dic[@"msg"]];
        }
    } failureBlock:^(NSError *error) {
        
    }];
    
    
}

- (void)renji {
    // 1 、先人机验证
    _img1.hidden = NO;
    _img2.hidden = NO;
    _img3.hidden = NO;
    _img4.hidden = NO;
    _img5.hidden = NO;
    _img6.hidden = NO;
    _img7.hidden = NO;
    _img8.hidden = NO;
    _img9.hidden = NO;
    
    RequestParams *params = [[RequestParams alloc] initWithParams:@"http://39.100.201.239:5588/api/api.php?action=machine_init"];
    [params addParameter:@"appkey" value:_appkey]; //
    [params addParameter:@"session_id" value:@""];
    [params addParameter:@"user_id" value:@""];
    [params addParameter:@"language" value:@"zh"];
    [params addParameter:@"platform" value:@"ios"];
    [params addParameter:@"randkey" value:@"ios 1.0.3"];
    [params addParameter:@"app_version" value:@"1.0.3"];
    [params addParameter:@"mac" value:_mac];//
    [params addParameter:@"mackey" value:_macKey];//
    
    [params addParameter:@"device_id" value:_device_id];//
    [params addParameter:@"device_ip" value:_device_ip];//
    [[NetworkSingleton shareInstace] sessionPost:params withTitle:@"" successBlock:^(id data) {
        NSDictionary *dic = [NSDictionary dictionaryWithDictionary:data];
        NSLog(@"人机验证数据==%@",dic);
        NSString *code = dic[@"code"];
        if ([code isEqualToString:@"5000"]) {
            [SVProgressHUD showSuccessWithStatus:dic[@"data"][0][@"machine_quetion"]];
            [_img1 sd_setImageWithURL:[NSURL URLWithString:dic[@"data"][0][@"machine_img_array"][0][@"img"]]];
            [_img2 sd_setImageWithURL:[NSURL URLWithString:dic[@"data"][0][@"machine_img_array"][1][@"img"]]];
            [_img3 sd_setImageWithURL:[NSURL URLWithString:dic[@"data"][0][@"machine_img_array"][2][@"img"]]];
            [_img4 sd_setImageWithURL:[NSURL URLWithString:dic[@"data"][0][@"machine_img_array"][3][@"img"]]];
            [_img5 sd_setImageWithURL:[NSURL URLWithString:dic[@"data"][0][@"machine_img_array"][4][@"img"]]];
            [_img6 sd_setImageWithURL:[NSURL URLWithString:dic[@"data"][0][@"machine_img_array"][5][@"img"]]];
            [_img7 sd_setImageWithURL:[NSURL URLWithString:dic[@"data"][0][@"machine_img_array"][6][@"img"]]];
            [_img8 sd_setImageWithURL:[NSURL URLWithString:dic[@"data"][0][@"machine_img_array"][7][@"img"]]];
            [_img9 sd_setImageWithURL:[NSURL URLWithString:dic[@"data"][0][@"machine_img_array"][8][@"img"]]];
            _machine_img_array = [NSArray arrayWithArray:dic[@"data"][0][@"machine_img_array"]];
            _machine_id = dic[@"data"][0][@"machine_id"];
        }else {
            [SVProgressHUD showErrorWithStatus:dic[@"msg"]];
        }
        
        
    } failureBlock:^(NSError *error) {
        
    }];
}

- (IBAction)tocreatAction:(id)sender {
    [self create];
}

- (void)create {
    
    RequestParams *params = [[RequestParams alloc] initWithParams:@"http://39.100.201.239:5588/api/api.php?action=invest_create"];
    [params addParameter:@"appkey" value:_appkey]; //
    [params addParameter:@"session_id" value:_session_id];
    [params addParameter:@"user_id" value:_user_id];
    [params addParameter:@"language" value:@"zh"];
    [params addParameter:@"platform" value:@"ios"];
    [params addParameter:@"randkey" value:@"ios 1.0.3"];
    [params addParameter:@"app_version" value:@"1.0.3"];
    [params addParameter:@"mac" value:_mac];//
    [params addParameter:@"mackey" value:_macKey];//
    
    [params addParameter:@"pay_coin_type" value:@"CDY"];//
    [params addParameter:@"invest_type" value:_invest_type];
    [params addParameter:@"invest_money" value:@"30"];
    [params addParameter:@"process_number" value:_process_number];
    [params addParameter:@"trade_password" value:@"999999"];
    [params addParameter:@"machine_id" value:_machine_id];//
    
    NSArray *views = @[_img1,_img2,_img3,_img4,_img5,_img6,_img7,_img8,_img9];
    NSMutableArray *array = [NSMutableArray array];
    for (UIImageView *sub in views) {
        if (sub.hidden) {
            [array addObject:_machine_img_array[[views indexOfObject:sub]][@"value"]];
        }
    }
    [params addParameter:@"machine_value" value:[array componentsJoinedByString:@""]];//
    [[NetworkSingleton shareInstace] sessionPost:params withTitle:@"" successBlock:^(id data) {
        NSDictionary *dic = [NSDictionary dictionaryWithDictionary:data];
        NSString *code = dic[@"code"];
        if ([code isEqualToString:@"5000"]) {
            [SVProgressHUD showSuccessWithStatus:@"投资成功"];
        }else {
            [SVProgressHUD showErrorWithStatus:dic[@"msg"]];
        }
    } failureBlock:^(NSError *error) {
        
    }];
    
}

// 生成字符串长度
#define kRandomLength 32
- (NSString *)serial
{
    //1.UUIDString
   // NSString *string = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    
    //2.时间戳
    NSTimeInterval time = [[NSDate date] timeIntervalSince1970];
    NSString *timeStr = [NSString stringWithFormat:@"%.0f",time];
    
    //3.随机字符串kRandomLength位  @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    static const NSString *kRandomAlphabet = @"abcdefghijklmnopqrstuvwxyz0123456789";
    NSMutableString *randomString = [NSMutableString stringWithCapacity: kRandomLength];
    for (int i = 0; i < kRandomLength; i++) {
        [randomString appendFormat: @"%C", [kRandomAlphabet characterAtIndex:arc4random_uniform((u_int32_t)[kRandomAlphabet length])]];
    }
    
    //==> UUIDString去掉最后一项,再拼接上"时间戳"-"随机字符串kRandomLength位"
    //NSMutableArray *array = [[NSMutableArray alloc] initWithArray:[string componentsSeparatedByString:@"-"]];
    NSMutableArray *array = [NSMutableArray array];
   // [array removeLastObject];
    [array addObject:randomString];
    [array addObject:timeStr];
    return [array componentsJoinedByString:@""];
}

#define kMACLength 32
- (NSString *)mac
{
    //1.UUIDString
   // NSString *string = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    
    //2.时间戳
//    NSTimeInterval time = [[NSDate date] timeIntervalSince1970];
//    NSString *timeStr = [NSString stringWithFormat:@"%.0f",time];
//
    //3.随机字符串kRandomLength位  @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    static const NSString *kRandomAlphabet = @"abcdefghijklmnopqrstuvwxyz0123456789";
    NSMutableString *randomString = [NSMutableString stringWithCapacity: kMACLength];
    for (int i = 0; i < kMACLength; i++) {
        [randomString appendFormat: @"%C", [kRandomAlphabet characterAtIndex:arc4random_uniform((u_int32_t)[kRandomAlphabet length])]];
    }
    
    //==> UUIDString去掉最后一项,再拼接上"时间戳"-"随机字符串kRandomLength位"
    //NSMutableArray *array = [[NSMutableArray alloc] initWithArray:[string componentsSeparatedByString:@"-"]];
    NSMutableArray *array = [NSMutableArray array];
   // [array removeLastObject];
    [array addObject:randomString];
    //[array addObject:timeStr];
    return [array componentsJoinedByString:@""];
}

// 18ABED8D-828D-4B6D-93A1-B0FB84082389

- (NSString *)get_device_id
{
    //1.UUIDString
   // NSString *string = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    
    //2.时间戳
    
    //3.随机字符串kRandomLength位  @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    static const NSString *kRandomAlphabet = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    NSMutableString *randomString1 = [NSMutableString stringWithCapacity: 8];
    NSMutableString *randomString2 = [NSMutableString stringWithCapacity: 4];
    NSMutableString *randomString3 = [NSMutableString stringWithCapacity: 4];
    NSMutableString *randomString4 = [NSMutableString stringWithCapacity: 4];
    NSMutableString *randomString5 = [NSMutableString stringWithCapacity: 12];
    for (int i = 0; i < 8; i++) {
        [randomString1 appendFormat: @"%C", [kRandomAlphabet characterAtIndex:arc4random_uniform((u_int32_t)[kRandomAlphabet length])]];
    }
    for (int i = 0; i < 4; i++) {
        [randomString2 appendFormat: @"%C", [kRandomAlphabet characterAtIndex:arc4random_uniform((u_int32_t)[kRandomAlphabet length])]];
    }
    for (int i = 0; i < 4; i++) {
        [randomString3 appendFormat: @"%C", [kRandomAlphabet characterAtIndex:arc4random_uniform((u_int32_t)[kRandomAlphabet length])]];
    }
    for (int i = 0; i < 4; i++) {
        [randomString4 appendFormat: @"%C", [kRandomAlphabet characterAtIndex:arc4random_uniform((u_int32_t)[kRandomAlphabet length])]];
    }
    for (int i = 0; i < 12; i++) {
        [randomString5 appendFormat: @"%C", [kRandomAlphabet characterAtIndex:arc4random_uniform((u_int32_t)[kRandomAlphabet length])]];
    }
    //==> UUIDString去掉最后一项,再拼接上"时间戳"-"随机字符串kRandomLength位"
    //NSMutableArray *array = [[NSMutableArray alloc] initWithArray:[string componentsSeparatedByString:@"-"]];
    NSMutableArray *array = [NSMutableArray array];
   // [array removeLastObject];
    [array addObject:randomString1];
    [array addObject:randomString2];
    [array addObject:randomString3];
    [array addObject:randomString4];
    [array addObject:randomString5];
    //[array addObject:timeStr];
    return [array componentsJoinedByString:@"-"];
}

// 生成随机ip
- (NSString *)get_device_ip{
    int value1 = (arc4random() % 254) + 1;
    int value2 = (arc4random() % 254) + 1;
    int value3 = (arc4random() % 254) + 1;
    int value4 = (arc4random() % 254) + 1;
    return [NSString stringWithFormat:@"%d.%d.%d.%d",value1,value2,value3,value4];
}

@end
